import { getLoginUser } from '@/apis'
import { useUserStore } from '@/stores'
import { useEffect } from 'react'
import type { FC, PropsWithChildren } from 'react'

export const Auth: FC<PropsWithChildren> = ({ children }) => {
  const setUser = useUserStore((state) => state.setUser)

  useEffect(() => {
    async function getUser() {
      const res = await getLoginUser()
      if (res.data.code === 0 && res.data.data) {
        setUser(res.data.data)
      }
    }
    getUser()
  }, [])
  return <>{children}</>
}
